package com.lam.Animation;

import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;

import com.lam.fundamental.R;

public class PropAnimation extends Activity implements OnClickListener{

	private Button bt_fzButton;
	private Button bt_fadeoutButton;
	private Button bt_pyButton;
	
	private ImageView iv_animation;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.propanimation);
		
		bt_fzButton=(Button)findViewById(R.id.bt_animation_fz);
		bt_fadeoutButton=(Button)findViewById(R.id.bt_animation_dc);
		bt_pyButton=(Button)findViewById(R.id.bt_animation_py);
		
		iv_animation=(ImageView)findViewById(R.id.iv_animation);
		bt_fzButton.setOnClickListener(this);
		bt_fadeoutButton.setOnClickListener(this);
		bt_pyButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bt_animation_fz:
			 ObjectAnimator//  
	         .ofFloat(iv_animation, "rotationX", 0.0F, 360.0F)//  
	         .setDuration(500)//  
	         .start();  
			break;
		case R.id.bt_animation_dc:
			
			 ObjectAnimator anim = ObjectAnimator//  
	            .ofFloat(iv_animation, "zhy", 1.0F,  0.0F)//  
	            .setDuration(500);//  
	    anim.start();  
	    anim.addUpdateListener(new AnimatorUpdateListener()  
	    {  
	        @Override  
	        public void onAnimationUpdate(ValueAnimator animation)  
	        {  
	            float cVal = (Float) animation.getAnimatedValue();  
	            iv_animation.setAlpha(cVal);  
	            iv_animation.setScaleX(cVal);  
	            iv_animation.setScaleY(cVal);  
	        }  
	    });  
	    break;
		case R.id.bt_animation_py:
			 ValueAnimator valueAnimator = new ValueAnimator();  
		        valueAnimator.setDuration(3000);  
		        valueAnimator.setObjectValues(new PointF(0, 0));  
		        valueAnimator.setInterpolator(new LinearInterpolator());  
		        valueAnimator.setEvaluator(new TypeEvaluator<PointF>()  
		        {  
		            // fraction = t / duration  
		            @Override  
		            public PointF evaluate(float fraction, PointF startValue,  
		                    PointF endValue)  
		            {  
		                
		                // x方向200px/s ，则y方向0.5 * 10 * t  
		                PointF point = new PointF();  
		                point.x = 200 * fraction * 3;  
		                point.y = 0.5f * 200 * (fraction * 3) * (fraction * 3);  
		                return point;  
		            }  
		        });  
		  
		        valueAnimator.start();  
		        valueAnimator.addUpdateListener(new AnimatorUpdateListener()  
		        {  
		            @Override  
		            public void onAnimationUpdate(ValueAnimator animation)  
		            {  
		                PointF point = (PointF) animation.getAnimatedValue();  
		                iv_animation.setX(point.x);  
		                iv_animation.setY(point.y);  
		  
		            }  
		        });  
		        break;
		default:
			break;
		}
	}

}
